
export function extractStrictJSON<T>(str: string): T | undefined {
  // 匹配严格符合 JSON 语法的 {} 或 []
  const strictJsonRegex = /(\{(?:[^{}]|(?:\{[^{}]*\}))*\}|\[(?:[^\[\]]|(?:\{[^{}]*\}))*\])/;
  const match = str.match(strictJsonRegex);

  if (!match) return undefined;

  try {
    return JSON.parse(match[0]);
  } catch (err) {
    return undefined;
  }
}